<?PHP
	require 'includes/master.inc.php';

	$where = '';
	if(isset($_GET['app_id']))
	{
		$app = new App($_GET['app_id']);
		if($app->id != "")
			$where .= 'appname = ' . $db->quote($app->sparkle_name) . ' AND ';
	}

	if(isset($_GET['type']) && in_array($_GET['type'], array('support', 'bug', 'feature')))
		$where .= "type = '{$_GET['type']}' AND ";
	else
		$_GET['type'] = 'all';

	$fb = new Feedback();
	$feedback = $fb->glob("WHERE $where deleted = 0 ORDER BY id DESC");

	$a = new App();
	$apps = $a->glob("ORDER BY name");

	$auth->admin();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>Feedback | Appcaster</title>
	<?PHP include 'inc/meta.inc.php'; ?>
	<link rel="alternate" type="application/rss+xml" title="All Feedback" href="<?PHP WEBROOT();?>feedback.php?act=rss" />
	<link rel="alternate" type="application/rss+xml" title="Suport Questions" href="<?PHP WEBROOT();?>feedback.php?act=rss&amp;type=support" />
	<link rel="alternate" type="application/rss+xml" title="Bug Reports" href="<?PHP WEBROOT();?>feedback.php?act=rss&amp;type=bug" />
	<link rel="alternate" type="application/rss+xml" title="Feature Requests" href="<?PHP WEBROOT();?>feedback.php?act=rss&amp;type=feature" />
	<script type="text/javascript" charset="utf-8">
		$(function() {
			$('#app_id').change(function() {
				window.location = 'feedback.php?app_id=' + $('#app_id').val();
			});	
		});
	</script>
</head>

<body id="home">
	<?PHP include 'inc/head.inc.php'; ?>
	<div id="nav">
		<ul>
			<li><a href='<?PHP WEBROOT();?>'>Applications</a></li>
			<li><a href='<?PHP WEBROOT();?>orders.php'>Orders</a></li>
			<li class='selected'><a href='<?PHP WEBROOT();?>feedback.php'>Feedback (<?PHP echo Feedback::newCountTotal();?>)</a></li>
			<li><a href='<?PHP WEBROOT();?>stats.php'>Stats</a></li>
			<li><a href='<?PHP WEBROOT();?>options.php'>Options</a></li>
		</ul>
	</div>

	<div id="menutabs">
		<ul id="tabnav">
			<li <?PHP if($_GET['type'] == 'all') echo "class='selected'";?>><a href="feedback.php">All Feedback</a></li>
			<li <?PHP if($_GET['type'] == 'support') echo "class='selected'";?>><a href="feedback.php?type=support">Support Questions</a></li>
			<li <?PHP if($_GET['type'] == 'bug') echo "class='selected'";?>><a href="feedback.php?type=bug">Bug Reports</a></li>
			<li <?PHP if($_GET['type'] == 'feature') echo "class='selected'";?>><a href="feedback.php?type=feature">Feature Requests</a></li>
		</ul>
	</div>

	<div id="contain">
		<!-- <p>Application:
			<select name="app_id" id="app_id">
				<option value="">All</option>
				<?PHP echo get_options('apps', 'id', 'name', isset($_GET['app_id']) ? $_GET['app_id'] : null); ?>
			</select>
		</p> -->

		<table class="grid feedback">
			<tr>
				<th>ID</th>
				<th>Application</th>
				<th>Type</th>
				<th>Email</th>
				<th>Want Reply?</th>
				<th>Date</th>
				<th>&nbsp;</th>
			</tr>
			<?PHP foreach($feedback as $f) : ?>
			<tr class="<?PHP if($f->new == 1) echo 'new';?> <?PHP if($f->critical == 1) echo 'critical';?>">
				<td><?PHP echo $f->id; ?></td>
				<td><?PHP echo $f->appname . ' ' . $f->appversion; ?></td>
				<td><?PHP echo ucwords($f->type); ?></td>
				<td><a href="mailto:<?PHP echo $f->email;?>"><?PHP echo $f->email; ?></a></td>
				<td><?PHP echo ($f->reply == 1) ? 'Yes' : 'No'; ?></td>
				<td><?PHP echo time2str($f->dt); ?></td>
				<td><a href="view-feedback.php?id=<?PHP echo $f->id;?>" style="display:block;text-align:center;">View</a></td>
			</tr>
			<?PHP endforeach; ?>
		</table>
	</div>
</body>
</html>